<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <?php
  //获取学号
  if ($_POST['stuno']) {
    $stuno = $_POST['stuno'];
  } else {
    $stuno = '没有填写';
  }

  //  暂存临时文件
  switch ($_FILES['photo']['error']) {
    case 0:
      $filetypes = ['image/gif', 'image/pjpeg', 'image/jpeg', 'image/png'];
      $type = $_FILES['photo']['type'];
      if (in_array($type, $filetypes)) {
        $filename = $_FILES['photo']['name'];
        $tmp = explode('.', $filename);
        $newname = $stuno . "." . $tmp[1];
        $destination = "Upload/" . $newname;
        move_uploaded_file($_FILES['photo']['tmp_name'], $destination);
      } else {
        $txt = "文件类型不符合要求";
      }
      break;
    case 1:
      $txt = "上传文件大小超过PHP的2MB限制!";
      break;
    case 4:
      $txt = "没有上传照片!";
      break;
  }
  ?>
  <h1>注册成功，您的注册信息如下：</h1>
  学号：<?= $stuno ?>
  <br>
  相片：<?php
      if (isset($txt)) {
        echo $txt;
      } else {
        echo "<img src='$destination' style='width: 150px;height: 120px;' />";
      }
      ?>
</body>
</html>